<template>
	<view class="pagebg">
		<view id="map" style="width: 100vw; height: 100vh;"></view>
		<!-- <tabbarVue :current="0"></tabbarVue> -->
	</view>
</template>

<script setup>
	import tabbarVue from '@/components/tabbar/index.vue'
	import {
		mymap
	} from '@/utils/BMap.js'
	import {
		ref,
	} from 'vue'
	import {
		onShow,
		onLoad
	} from '@dcloudio/uni-app'
	
	const ak = ref('tk1c97qBl7PegAOyBk7UHbNQe97a2n4k')
	const map = ref(null)
	const getLocation = () => {
		let geolocation = new BMap.Geolocation();
		return new Promise((resolve, reject) => {
			geolocation.getCurrentPosition(function(r) {
				if (this.getStatus() == BMAP_STATUS_SUCCESS) {
					var mk = new BMap.Marker(r.point);
					console.log(mk);
					resolve(r.point)
					// console.log('您的位置：' + r.point.lng + ',' + r.point.lat);
				} else {
					console.log('failed' + this.getStatus());
					reject('failed' + this.getStatus());
				}
			})
		})
	}


	const initBaiduMap = async () => {
		mymap(ak.value).then(async mymap => {
			BMap = BMap;
			const location = await getLocation()
			map.value = new BMap.Map('map');
			const point = new BMap.Point(116.404, 39.925);
			map.value.centerAndZoom(point, 15)
			// map.value.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
		})
	}

	onLoad(() => {
		if (typeof window._baiduMapInit === 'function') {
			window._baiduMapInit = initBaiduMap;
		} else {
			initBaiduMap();
		}
	})
	onShow(() => {
		uni.hideTabBar()
	})
</script>

<style>
	page {
		background: #ffffff;
	}
</style>
<style lang="scss" scoped>

</style>